package com.fuershiye.woman.monitor.controller;

import java.util.List;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fuershiye.woman.monitor.model.Unit;
import com.fuershiye.woman.monitor.service.UnitService;

@Controller
@RequestMapping(value = "/manager/unit")
public class UnitController {
	
    @Autowired
    UnitService unitService;
    
//    @RequiresPermissions("managerUnit:view")
    @RequestMapping(value="/view.do")
    public String view(String show){
        return "unit/" + show;
    }
    
//    @RequiresPermissions("managerUnit:save")
    @RequestMapping(value = "/save.do")
    @ResponseBody
    public boolean save(String name, Long id) {
    	Unit unit = new Unit();
    	if(id!=null && id!=0){
        	unit = unitService.get(id);
    	}
    	unit.setName(name);
    	unit.setStatus(1);
    	unitService.save(unit);
    	return true;
    }
    
//    @RequiresPermissions("managerUnit:list")
    @RequestMapping(value="/list.do")
    @ResponseBody
    public List<Unit> unitlist(String name) {
    	return unitService.list(name, 1);
    }
    
//    @RequiresPermissions("managerUnit:delete")
    @RequestMapping(value="/delete.do")
    @ResponseBody
    public boolean delete(Long id) {
    	Unit u = unitService.get(id);
        u.setStatus(0);//修改为已删除
        unitService.save(u);
        return true;
    }

}
